import Expression from "../interface/Expression";
import MetaData from "../MetaData";

abstract class AbsExpression implements Expression {
    public type: "where" | "limit" | "abs" |"prefix"|"native" = "abs";
    protected metadata?: MetaData;

    public constructor(metadata?: MetaData) {
        this.metadata = metadata;
    }

    public toSql(completion: boolean = false): string {
        let sql = this.metadata?.expressionList.map(e => e.toLocaSql()).join(" ") || "";
        if (completion) {
            let i = 0;
            sql = sql.replace(/\?/g, () => {
                return this.metadata?.parameter[i++];
            })
        }
        return sql;
    };

    toLocaSql(): string {
        return "";
    }

    first(..._field: string[]): Promise<Record<string, any>> {
        return Promise.resolve({});
    }

    get(..._field: string[]): Promise<Array<Record<string, any>>> {
        return Promise.resolve([]);
    }

    value(_field: string): Promise<any> {
        return Promise.resolve(undefined);
    }

    delete(_check: boolean | string | Record<string, string | number | bigint | boolean> = true, _value?: string | number | bigint | boolean): Promise<number> {
        return Promise.resolve(0);
    }

    insert(_data: Array<Record<string, string | number | bigint | boolean>> | Record<string, string | number | bigint | boolean>): Promise<number> {
        return Promise.resolve(0);
    }

    insertId(_data: Record<string, string | number | bigint | boolean>): Promise<number> {
        return Promise.resolve(0);
    }

    update(_data: Array<Record<string, string | number | bigint | boolean>> | Record<string, string | number | bigint | boolean>): Promise<number> {
        return Promise.resolve(0);
    }


}

export = AbsExpression;